//
//  ShopFirstCell.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/6/15.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "ShopFirstCell.h"
#import "LPLabel.h"

@interface ShopFirstCell()
{
    //    NSString *sale;
    //    NSString *kucun;
}

@property (nonatomic,strong)UIButton *kucunButton;

@property (nonatomic,strong)UIButton *xiaoLiangButton;

@property(nonatomic,strong)UIButton *limitButton;

@end

@implementation ShopFirstCell

- (instancetype)init
{
    if (self = [super init]) {
        
        CGFloat fontH;
        if (iPhone5) {
            fontH = 14;
        }else if (iPhone6){
            fontH = 14;
        }else {
            fontH = 15;
        }
        
        self.nameLabel = [[UILabel alloc] init];
        _nameLabel.font = [UIFont systemFontOfSize:fontH];
        _nameLabel.textAlignment = NSTextAlignmentCenter;
        _nameLabel.numberOfLines = 0;
        [self.contentView addSubview:_nameLabel];
        _nameLabel.text = @" ";
        
        self.brandLabel = [[UILabel alloc] init];
        _brandLabel.font = [UIFont systemFontOfSize:13];
        _brandLabel.textAlignment = NSTextAlignmentCenter;
        _brandLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_brandLabel];
        _brandLabel.text = @" ";
        
        self.saleLabel = [[UILabel alloc] init];
        _saleLabel.font = [UIFont systemFontOfSize:18];
        _saleLabel.textAlignment = NSTextAlignmentCenter;
        _saleLabel.textColor = DEFAULT_COLOR;
        _saleLabel.font = [UIFont boldSystemFontOfSize:18];
        [self.contentView addSubview:_saleLabel];
        _saleLabel.text = @" ";
        
        self.totalLabel = [[LPLabel alloc] init];
        _totalLabel.strikeThroughEnabled = YES;
        _totalLabel.strikeThroughColor = [UIColor grayColor];
        _totalLabel.font = [UIFont systemFontOfSize:15];
        _totalLabel.textAlignment = NSTextAlignmentCenter;
        _totalLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_totalLabel];
         _totalLabel.text = @" ";
        

        self.postMoney = [[UILabel alloc] init];
        _postMoney.font = [UIFont systemFontOfSize:15];
        _postMoney.textAlignment = NSTextAlignmentCenter;
        _postMoney.textColor = [UIColor grayColor];
        [self.contentView addSubview:_postMoney];
        _postMoney.font = [UIFont boldSystemFontOfSize:15];
        _postMoney.text = @" ";
        
        CGFloat BtnW = WIDTH/5+10;
        CGFloat BtnMargin = (WIDTH-BtnW*3)/3;
        
        UIButton *button;
        NSString *str = [NSString stringWithFormat:@"%@",_limit_buy];
        NSString *sale = [NSString stringWithFormat:@"%@",_sale];
        NSString *kucun = [NSString stringWithFormat:@"%@",_kucun];
        NSMutableArray *arr = [NSMutableArray array];
        [arr addObject:str];
        [arr addObject:sale];
        [arr addObject:kucun];
        
        
        for (int i = 0; i < arr.count; ++i) {
            
            button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.titleLabel.font = [UIFont systemFontOfSize:13];
//            [button setTitle:[NSString stringWithFormat:@"%@",arr[i]] forState:UIControlStateNormal];
            [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
            button.tag = 1200+i;
            [button addTarget:self action:@selector(standChooseDidClick:) forControlEvents:UIControlEventTouchUpInside];
            
            [self.contentView addSubview:button];
            
            [button mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(_totalLabel.mas_bottom).offset(5);
                make.left.mas_equalTo(BtnMargin+(BtnW+BtnMargin/2.5)*i);
                make.width.mas_equalTo(BtnW);
            }];
            
            if (i == 1) {
                self.xiaoLiangButton = button;
            } else if (i == 2) {
                self.kucunButton = button;
            }else{
                self.limitButton = button;
            }
        }
        
        
        for (int i = 0; i < 2; ++i) {
            UIView *threadView = [[UIView alloc] init];
            threadView.backgroundColor = [UIColor grayColor];
            threadView.alpha = 0.7;
            [self.contentView addSubview:threadView];
            
            [threadView mas_makeConstraints:^(MASConstraintMaker *make) {
                
                make.top.equalTo(_totalLabel.mas_bottom).offset(11);
                make.width.mas_equalTo(1);
                make.height.mas_equalTo(self.Height/3);
                make.left.mas_equalTo(BtnMargin+BtnMargin/2.5/2+BtnW+(BtnW+BtnMargin/2.5)*i);
            }];
        }
        
        
        
        CGFloat margin = 15;
        CGFloat topMar = self.Height/6;
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.width.mas_equalTo(WIDTH - margin*2);
            make.top.mas_equalTo(10);
        }];
        
        [_brandLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.width.mas_equalTo(WIDTH - margin*2);
            make.top.equalTo(_nameLabel.mas_bottom).offset(topMar);
        }];
        
        [_saleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX).offset(-WIDTH/7);
            make.top.equalTo(_brandLabel.mas_bottom).offset(topMar);
        }];
        
        [_totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_saleLabel.mas_bottom);
            make.left.equalTo(_saleLabel.mas_right).offset(margin);
        }];
        
        
        [_postMoney mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_saleLabel.mas_bottom);
            make.left.equalTo(_totalLabel.mas_right).offset(margin+5);
        }];
        
        
    }
    return self;
}

- (void)setSale:(NSString *)sale
{
    _sale = sale;
    [self.xiaoLiangButton setTitle:sale forState:UIControlStateNormal];
}

- (void)setKucun:(NSString *)kucun
{
    _kucun = kucun;
    [self.kucunButton setTitle:kucun forState:UIControlStateNormal];
}

- (void)setLimit_buy:(NSString *)limit_buy
{
    _limit_buy = limit_buy;
    [self.limitButton setTitle:_limit_buy forState:UIControlStateNormal];
    self.limitButton.titleLabel.font = [UIFont boldSystemFontOfSize:13];
    [self.limitButton setTitleColor:DEFAULT_COLOR forState:UIControlStateNormal];
}

- (void)standChooseDidClick:(UIButton *)button
{
    
}

@end
